#coding=utf-8
'''
Created 2016.6.3
@author: DQA wangpeng
'''
import unittest
import HTMLTestRunner
import os
import time
from selenium import webdriver
import sys
import choose_mobile
reload(sys)
sys.setdefaultencoding('utf8')
from testcase import *
import allcase_list
import shutil
import time
def huawei_5x():
    alltestnames = allcase_list.huawei_5x()
    #build a suite
    #创建测试套件
    testunit = unittest.TestSuite()
    #循环读取数组中的用例
    for test in alltestnames:
        testunit.addTest(unittest.makeSuite(test))
    
    #定义报告存放路径，支持相对路径
    testmobile = 'huawei_5x'    
    filename =  'E:\\eclipse\\huawei_rader\\all_mobile\\'+ testmobile + '_result.html'
    fp = file(filename,'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                stream = fp,
                title = u'华为小雷达自动化测试报告 --测试手机：华为5x' ,
                description = u'用例执行情况请查看下图所示：绿色代表PASS,Fail代表出现Bug，Error代表代码中途挂掉或者机器出现死机等非预期现象，(分别点击PASS,Fail，Error可以查看具体测试内容)。测试环境：APP:V0.3.8,BLE:V0.3.8,附件：V0.3.8 ：'                            
            )
    
    runner.run(testunit)
    #shutil.copy(r'E:\eclipse\huawei_rader\all_mobile\report\huawei_5x', r'\\10.84.100.35\auto_test\report_save\huawei_radar\huawei_5x')
    import mailattach_huawei_5x
    target = r'\\10.84.100.35\auto_test\report_save\huawei_radar\huawei_5x\\'
    currenttime = time.strftime("%Y_%m_%d_%H_%M_%S")
    addtarget = target + currenttime
    print addtarget
    shutil.copytree(r'E:\eclipse\huawei_rader\all_mobile\report\huawei_5x', addtarget)
    print '华为5X测试完毕，请重新更换其他手机继续测试，good luck'

def huawei_honor6():
    alltestnames = allcase_list.huawei_honor6()
    #build a suite
    #创建测试套件
    testunit = unittest.TestSuite()
    #循环读取数组中的用例
    for test in alltestnames:
        testunit.addTest(unittest.makeSuite(test))
    
    #定义报告存放路径，支持相对路径
    testmobile = 'huawei_honor6'    
    filename =  'E:\\eclipse\\huawei_rader\\all_mobile\\'+ testmobile + '_result.html'
    fp = file(filename,'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                stream = fp,
                title = u'华为小雷达自动化测试报告 --测试手机：华为荣耀6手机' ,
                description = u'用例执行情况请查看下图所示：绿色代表PASS,Fail代表出现Bug，Error代表代码中途挂掉(分别点击PASS,Fail，Error可以查看具体测试内容)。测试环境：APP:V0.3.7,BLE:V0.3.7,附件：V0.3.7 ：'                            
            )
    
    runner.run(testunit)
    #shutil.copy(r'E:\eclipse\huawei_rader\all_mobile\report\huawei_5x', r'\\10.84.100.35\auto_test\report_save\huawei_radar\huawei_5x')
    import mailattach_huawei_honor6
    target = r'\\10.84.100.35\auto_test\report_save\huawei_radar\huawei_honor6\\'
    currenttime = time.strftime("%Y_%m_%d_%H_%M_%S")
    addtarget = target + currenttime
    print addtarget
    shutil.copytree(r'E:\eclipse\huawei_rader\all_mobile\report\huawei_honor6', addtarget)
    print '华为荣耀6测试完毕，请重新更换其他手机继续测试，good luck'

def huawei_p8():
    alltestnames = allcase_list.huawei_p8()
    #build a suite
    #创建测试套件
    testunit = unittest.TestSuite()
    #循环读取数组中的用例
    for test in alltestnames:
        testunit.addTest(unittest.makeSuite(test))
    
    #定义报告存放路径，支持相对路径
    testmobile = 'huawei_p8'    
    filename =  'E:\\eclipse\\huawei_rader\\all_mobile\\'+ testmobile + '_result.html'
    fp = file(filename,'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                stream = fp,
                title = u'华为小雷达自动化测试报告 --测试手机：华为P8手机' ,
                description = u'用例执行情况请查看下图所示：绿色代表PASS,Fail代表出现Bug，Error代表代码中途挂掉或者机器出现死机等非预期现象，(分别点击PASS,Fail，Error可以查看具体测试内容)。测试环境：APP:V0.4.3,BLE:V0.4.4,附件：V0.4.2 ：'                            
            )
    
    runner.run(testunit)
    #shutil.copy(r'E:\eclipse\huawei_rader\all_mobile\report\huawei_5x', r'\\10.84.100.35\auto_test\report_save\huawei_radar\huawei_5x')
    import mailattach_huawei_p8
    target = r'\\10.84.100.35\auto_test\report_save\huawei_radar\huawei_p8\\'
    currenttime = time.strftime("%Y_%m_%d_%H_%M_%S")
    addtarget = target + currenttime
    print addtarget
    shutil.copytree(r'E:\eclipse\huawei_rader\all_mobile\report\huawei_p8', addtarget)
    print '华为P8测试完毕，请重新更换其他手机继续测试，good luck'

def huawei_mate8():
    alltestnames = allcase_list.huawei_mate8()
    print '开始测试华为mate8'
    #build a suite
    #创建测试套件
    testunit = unittest.TestSuite()
    #循环读取数组中的用例
    for test in alltestnames:
        testunit.addTest(unittest.makeSuite(test))
    
    #定义报告存放路径，支持相对路径
    testmobile = 'huawei_mate8'    
    filename =  'E:\\eclipse\\huawei_rader\\all_mobile\\'+ testmobile + '_result.html'
    fp = file(filename,'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                stream = fp,
                title = u'华为小雷达自动化测试报告 --测试手机：华为mate8手机' ,
                description = u'用例执行情况请查看下图所示：绿色代表PASS,Fail代表出现Bug，Error代表代码中途挂掉或者机器出现死机等非预期现象，(分别点击PASS,Fail，Error可以查看具体测试内容)。测试环境：APP:V0.3.8,BLE:V0.3.8,附件：V0.3.8 ：'                            
            )
    
    runner.run(testunit)
    
    #shutil.copy(r'E:\eclipse\huawei_rader\all_mobile\report\huawei_5x', r'\\10.84.100.35\auto_test\report_save\huawei_radar\huawei_5x')
    import mailattach_huawei_mate8

    #shutil.copytree(r'E:\eclipse\huawei_rader\all_mobile\report\huawei_mate8', addtarget)
    print '华为mate8测试完毕，请重新更换其他手机继续测试，good luck'
    

def lenovo_z90():
    alltestnames = allcase_list.lenovo_z90()
    #build a suite
    #创建测试套件
    testunit = unittest.TestSuite()
    #循环读取数组中的用例
    for test in alltestnames:
        testunit.addTest(unittest.makeSuite(test))
    
    #定义报告存放路径，支持相对路径
    testmobile = 'lenovo_z90'    
    filename =  'E:\\eclipse\\huawei_rader\\all_mobile\\'+ testmobile + '_result.html'
    fp = file(filename,'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                stream = fp,
                title = u'华为小雷达自动化测试报告 --测试手机：华为5x' ,
                description = u'用例执行情况请查看下图所示：绿色代表PASS,Fail代表出现Bug，Error代表代码中途挂掉或者机器出现死机等非预期现象，(分别点击PASS,Fail，Error可以查看具体测试内容)。测试环境：APP:V0.3.8,BLE:V0.3.8,附件：V0.3.8 ：'                            
            )
    
    runner.run(testunit)
    #shutil.copy(r'E:\eclipse\huawei_rader\all_mobile\report\lenovo_z90', r'\\10.84.100.35\auto_test\report_save\huawei_radar\lenovo_z90')
    
    import mailattach_lenovo_z90
    target = r'\\10.84.100.35\auto_test\report_save\huawei_radar\lenovo_z90\\'
    currenttime = time.strftime("%Y_%m_%d_%H_%M_%S")
    addtarget = target + currenttime
    print addtarget
    shutil.copytree(r'E:\eclipse\huawei_rader\all_mobile\report\lenovo_z90', addtarget)
    print '华为5X测试完毕，请重新更换其他手机继续测试，good luck'
    

def huawei_honor4A():
    alltestnames = allcase_list.huawei_honor4A()
    #build a suite
    #创建测试套件
    testunit = unittest.TestSuite()
    #循环读取数组中的用例
    for test in alltestnames:
        testunit.addTest(unittest.makeSuite(test))
    
    #定义报告存放路径，支持相对路径
    testmobile = 'huawei_honor4A'    
    filename =  'E:\\eclipse\\huawei_rader\\all_mobile\\'+ testmobile + '_result.html'
    fp = file(filename,'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                stream = fp,
                title = u'华为小雷达自动化测试报告 --测试手机：华为4A手机' ,
                description = u'用例执行情况请查看下图所示：绿色代表PASS,Fail代表出现Bug，Error代表代码中途挂掉或者机器出现死机等非预期现象，(分别点击PASS,Fail，Error可以查看具体测试内容)。测试环境：APP:V0.3.8,BLE:V0.3.8,附件：V0.3.8 ：'                            
            )
    
    runner.run(testunit)
    #shutil.copy(r'E:\eclipse\huawei_rader\all_mobile\report\lenovo_z90', r'\\10.84.100.35\auto_test\report_save\huawei_radar\lenovo_z90')
    
    import mailattach_huawei_honor4A
#     target = r'\\10.84.100.35\auto_test\report_save\huawei_radar\lenovo_z90\\'
#     currenttime = time.strftime("%Y_%m_%d_%H_%M_%S")
#     addtarget = target + currenttime
#     print addtarget
#     shutil.copytree(r'E:\eclipse\huawei_rader\all_mobile\report\lenovo_z90', addtarget)
    print '华为荣耀4A测试完毕，请重新更换其他手机继续测试，good luck'
    
if __name__ == '__main__':
    #all_mobile_list = ['huawei_honor7','huawei_5x']
    #0华为荣耀7手机，  1.代表华为5X手机   2:SONY Z3手机。。。。。。。

    if  choose_mobile.want_to_test_mobile == 'huawei_5x':
        huawei_5x()

    elif  choose_mobile.want_to_test_mobile == 'huawei_honor6':
        huawei_honor6()
        
    elif  choose_mobile.want_to_test_mobile == 'huawei_p8':
        huawei_p8()

    elif  choose_mobile.want_to_test_mobile == 'huawei_mate8':
        huawei_mate8()
        
    elif  choose_mobile.want_to_test_mobile == 'lenovo_z90':
        lenovo_z90()

    elif  choose_mobile.want_to_test_mobile == 'huawei_honor4A':
        huawei_honor4A()
    else:
        pass